Event Triggers
Event triggers allow BindAI applications to react when an event is published through anEventBus.
The EventTrigger class connects an event source to an application-defined callable:
EventTrigger
EventTrigger is provided by the bindai-automation package:
bus— theEventBusthat publishes events.event_name— the event name to subscribe to.target— the callable that receives matching events.
Creating a Target
The target is a normal callable that receives the published event.Attaching a Trigger
Creating anEventTrigger does not automatically subscribe it to the event bus.
Call:
handle_event.
Detaching a Trigger
A trigger can be removed from the event bus with:detach() when the trigger is already detached is safe.
Duplicate Attach Protection
EventTrigger prevents the same trigger from being attached multiple times.
For example:
Enabled and Disabled State
An attached trigger can be temporarily disabled.Disable
Detach
Trigger Lifecycle
The typical lifecycle is:Event Names
AnEventTrigger subscribes to a specific event name.
For example:
EventBus uses the event’s name property to determine which handlers should receive it.
The exact event names available depend on the events implemented by the BindAI event system.
BindAI Event Objects
BindAI events inherit from the coreEvent abstraction.
An event contains common information such as:
idtimestamppayloadname
EventTrigger passes the event object to the target without transforming it.
Agent Event Sources
Agents expose an event bus through:Tool Execution Events
Agent tool execution publishes aToolExecutedEvent through the agent’s event bus.
A trigger can react to that event.
For example:
EventTypes value used by the installed BindAI version.
Wildcard Events
The underlyingEventBus supports wildcard subscriptions using:
EventTrigger is configured with one specific event_name and subscribes directly to that name.
Applications that require broader event routing should use the underlying EventBus capabilities or a higher-level routing abstraction rather than assuming that EventTrigger itself provides pattern matching.
Advanced event routing is outside the current EventTrigger abstraction.
Multiple Event Triggers
An application can create multiple triggers for different events.Multiple Targets
Different triggers can use different targets:Shared Event Sources
Multiple triggers can subscribe to the same event bus. For example:Event Trigger and EventBus
The relationship between the two components is:EventTrigger is therefore an adapter between the core event system and automation logic.
It does not replace EventBus.
Event Handler Isolation
The coreEventBus isolates exceptions raised by individual event handlers.
For example, if a target raises an exception:
EventTrigger responsible for retry or recovery.
This behavior comes from the core EventBus, not from a separate retry system inside EventTrigger.
Applications requiring specific failure handling should implement that behavior at the appropriate higher-level automation or execution layer.
Synchronous Event Dispatch
The current BindAIEventBus is synchronous.
When an event is published, subscribed handlers are invoked during event publication.
Conceptually:
EventTrigger itself does not create a background worker.
It also does not persist events or queue automation jobs.
For automation definitions that require background execution, BindAI provides AutomationWorker as a separate execution abstraction.
This keeps event detection and background execution as separate concerns:
Background Automation Execution
AutomationWorker executes AutomationDefinition instances and manages their AutomationRun lifecycle.
It is separate from EventTrigger.
An application can use an event trigger to decide when an automation should start and then use an AutomationWorker to execute the automation in the background.
For example:
No Built-In Retry
The currentEventTrigger does not implement retry policies.
There is no built-in API such as:
No Trigger-Level Persistent State
The currentEventTrigger does not persist:
- Events
- Trigger executions
- Trigger history
- Retry state
EventTrigger itself.
In other words:
AutomationRun.
Using a Function as a Target
A simple function is often sufficient:Using a Callable Object
A callable class can also be used:EventTrigger.
Calling a Workflow from a Target
An application can use a target to invoke other BindAI functionality. Conceptually:Calling an Agent from a Target
The same pattern can be used with an agent:Using Connections from a Target
A target can also interact with a BindAI connection. For example:TriggerRegistry
Multiple triggers can be managed throughTriggerRegistry.
Managing Registered Triggers
The registry supports:Registry Does Not Attach Triggers
Registering a trigger does not itself attach it to an event bus. For example:Security
Event-driven automation can cause actions without direct user interaction. Targets should therefore be treated as potentially privileged application logic. Recommended practices include:- Validate event payloads.
- Avoid exposing secrets through events.
- Restrict state-changing actions.
- Apply appropriate authorization.
- Keep credentials outside event payloads.
- Avoid passing untrusted event data directly into sensitive operations.
- Audit important automated actions.
Event Payloads
Event payloads can contain application-specific information. A target can inspect:- API keys
- Access tokens
- Passwords
- Private credentials
Testing Event Triggers
Event triggers can be tested without external services. A typical test can:- Create an event bus.
- Create a test target.
- Create an event trigger.
- Attach the trigger.
- Publish an event.
- Verify that the target was called.
- Detach the trigger.
- Verify that later events are ignored.
received.
Testing Disable Behavior
Disable behavior should also be tested.Testing Detach Behavior
Detach behavior should verify that the subscription is removed:Testing Duplicate Attachment
Applications can verify that:Recommended Lifecycle
For application startup:AutomationWorker is being used, it should also be shut down during application shutdown:
Event Triggers and Automation Architecture
Event triggers form the event-driven entry layer of the broader BindAI Automation architecture. The trigger layer is:AutomationDefinitionAutomationRunAutomationStateStoreMemoryAutomationStateStoreAutomationRunHistoryMemoryAutomationRunHistoryAutomationWorker
EventTrigger.
For example, an application may use an event trigger to initiate an automation and then use the automation execution layer to track the resulting run.
The trigger itself does not automatically perform these operations.
Best Practices
Use event triggers when:- An application needs to react to BindAI events.
- Event handling should remain separate from the event source.
- A small callable is sufficient for the automation action.
- Trigger lifecycle needs to be controlled explicitly.
- Multiple event-driven actions need to coexist.
- Keep targets focused.
- Validate event payloads.
- Attach triggers deliberately.
- Detach triggers when no longer needed.
- Disable triggers when temporary suspension is sufficient.
- Keep secrets outside event payloads.
- Test trigger lifecycle independently.
- Keep execution state and run history in the appropriate automation layer.
- Use
AutomationWorkerwhen automation definitions require background execution.
- Putting large orchestration systems directly inside a target.
- Treating an event as automatic authorization for privileged operations.
- Assuming that event dispatch is asynchronous.
- Assuming built-in retries.
- Assuming that
EventTriggeritself provides persistent state or run history. - Assuming that
EventTriggeritself manages background worker lifecycle.
Current Scope
The currentEventTrigger implementation provides:
- Event bus subscription
- Named event matching through
EventBus - Callable targets
- Attach and detach lifecycle
- Enable and disable state
- Duplicate attachment protection
EventTrigger.
AutomationWorker provides explicit background execution for AutomationDefinition instances.
Advanced event routing, retry policies, persistent storage backends, and other higher-level execution capabilities remain separate concerns.
Summary
EventTrigger provides a small adapter between BindAI’s event system and application automation logic.
The core flow is:
EventTrigger focused on event subscription and lifecycle while allowing the broader automation layer to handle execution, state, history, and background work.